package com.larry.spring.config;

import com.larry.spring.bean.Cat;
import com.larry.spring.bean.Person;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.*;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @ProjectName spring
 * @Author larry
 * @Date 21:16 2021/9/2
 * @Description 配置类
 **/

//@Import({MainConfig.MyImportRegistrar.class})
@ComponentScan("com.larry.spring")
@Configuration
public class MainConfig {

	//@Bean
	public Person person(){
		Person person = new Person();
		person.setUsername("张三");
		return person;
	}


	/**
	 * BeanDefinitionRegistry -->Bean定义信息注册中心
	 * 		BeanDefinition
	 */
	static class MyImportRegistrar implements ImportBeanDefinitionRegistrar{
		@Override
		public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

			RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
			rootBeanDefinition.setBeanClass(Cat.class);
			//BeanDefinition
			registry.registerBeanDefinition("cat",rootBeanDefinition);
		}
	}

}
